package com.xuexiang.xuidemo.page.text;

import ohos.agp.components.Component;

import com.xuexiang.xui_lib.component.textview.marqueen.LabelButtonView;
import com.xuexiang.xui_lib.component.textview.marqueen.LabelImageView;
import com.xuexiang.xui_lib.component.textview.marqueen.LabelTextView;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;

/**
 * LabelView示例页面
 *
 * @since 2021-04-06
 */
@Page(name = "LabelView", subTitle = "标签", action = "LabelViewAbilitySlice", ability = TextAbility.class)
public class LabelViewAbilitySlice extends BasePageAbilitySlice implements Component.ClickedListener {
    private static final int TWENTY = 20;
    private static final int THIRTY = 30;
    private static final int FOUR = 4;
    private LabelButtonView btnLabel;
    private LabelImageView ivLabel;
    private LabelTextView tvLabel;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_lable_view;
    }

    @Override
    protected void onActive() {
        super.onActive();
        findView();
    }

    private void findView() {
        btnLabel = findCastComponentById(ResourceTable.Id_btn_label);
        ivLabel = findCastComponentById(ResourceTable.Id_iv_label);
        tvLabel = findCastComponentById(ResourceTable.Id_tv_label);

        btnLabel.setClickedListener(this);
        ivLabel.setClickedListener(this);
        tvLabel.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_label:
                btnLabel.setLabelVisual(!btnLabel.isLabelVisual());
                break;
            case ResourceTable.Id_iv_label:
                ivLabel.setLabelDistance((int) (Math.random() * TWENTY + THIRTY));
                break;
            case ResourceTable.Id_tv_label:
                tvLabel.setLabelOrientation((int) (Math.random() * FOUR + 1));
                break;
            default:
                break;
        }
    }
}
